\defmodule {RandomVariateGenInt}

This is the base class for all generators of discrete random variates
over the set of integers.
Similar to \class{RandomVariateGen}{}, except that the generators
produce integers, via the \method{nextInt}{} method, instead of real numbers.


\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        RandomVariateGenInt
 * Description:  base class for all generators of discrete random variates
over the integers
 * Environment:  Java
 * Software:     SSJ
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.RandomStream;
import umontreal.iro.lecuyer.probdist.DiscreteDistributionInt;\end{hide}

public class RandomVariateGenInt extends RandomVariateGen\begin{hide} {

\end{hide}
\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Constructor}
\begin{code}\begin{hide}
   protected RandomVariateGenInt() {}\end{hide}

   public RandomVariateGenInt (RandomStream s, DiscreteDistributionInt dist) \begin{hide} {
      this.stream = s;
      this.dist   = dist;
   }\end{hide}
\end{code}
  \begin{tabb}  Creates a new random variate generator for the discrete
    distribution \texttt{dist}, using stream \texttt{s}.
 \end{tabb}
\begin{htmlonly}
   \param{s}{random stream used for generating uniforms}
   \param{dist}{discrete distribution object of the generated values}
\end{htmlonly}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Methods}
\begin{code}

   public int nextInt() \begin{hide} {
      return ((DiscreteDistributionInt) dist).inverseFInt (stream.nextDouble());
   }\end{hide}
\end{code}
  \begin{tabb}
    Generates a random number (an integer) from the discrete
    distribution contained in this object.
    By default, this method uses inversion by calling the \texttt{inverseF}
    method of the distribution object.
    Alternative generating methods are provided in subclasses.
 \end{tabb}
\begin{htmlonly}
   \return{the generated value}
\end{htmlonly}
\begin{code}

   public void nextArrayOfInt (int[] v, int start, int n) \begin{hide} {
      if (n < 0)
         throw new IllegalArgumentException ("n must be positive.");
      for (int i = 0; i < n; i++)
         v[start + i] = nextInt();
   }\end{hide}
\end{code}
  \begin{tabb} Generates \texttt{n} random numbers from the discrete distribution
    contained in this object.  The results are stored into the array \texttt{v},
    starting from index \texttt{start}.
    By default, this method calls \method{nextInt()}{} \texttt{n}
   times, but one can reimplement it in subclasses for better efficiency.
 \end{tabb}
\begin{htmlonly}
   \param{v}{array into which the variates will be stored}
   \param{start}{starting index, in \texttt{v}, of the new variates}
   \param{n}{number of variates being generated}
\end{htmlonly}
\begin{code}

   public DiscreteDistributionInt getDistribution() \begin{hide} {
      return (DiscreteDistributionInt) dist;
   }\end{hide}
\end{code}
\begin{tabb}
  Returns the \class{DiscreteDistributionInt} used by this generator.
\end{tabb}
\begin{htmlonly}
   \return{the distribution associated to that object}
\end{htmlonly}
\begin{code}\begin{hide}
}\end{hide}
\end{code}
